﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SerienNewsReader
{
    /// <summary>
    /// Interaction logic for OptionsDialog.xaml
    /// </summary>
    public partial class OptionsDialog : Window
    {
        /// <summary>
        /// Initializes a new instance of OptionsDialog class
        /// </summary>
        public OptionsDialog()
        {
            InitializeComponent();
            this.CustomInitialize();
        }

        /// <summary>
        /// Loads all current settings
        /// </summary>
        private void CustomInitialize()
        {
            this.textBoxSeries.Text = SerienNewsReader.config.Default.Series;
        }

        /// <summary>
        /// Prepares the series string for saving, saves the settings and closes the options dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            string titles = this.textBoxSeries.Text;
            if (!titles.EndsWith(";"))
            {
                titles = titles + ";";
            }

            SerienNewsReader.config.Default.Series = titles;
            SerienNewsReader.config.Default.Save();
            this.Close();
        }

        /// <summary>
        /// Closes the options dialog without saving the settings
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
